package com.menu;

import com.company.SortLink;

import java.io.IOException;
import java.util.Scanner;

public class SortLinkMenu {
    public void linkMenu() throws IOException {
        boolean flag = true;
        while (flag){
            System.out.println("\\n请选择排序的方法：\\n");
            System.out.println("\t1.链表的快速排序");
            System.out.println("\t2.链表的选择排序\\n");
            System.out.println("\t3.链表的归并排序\\n");
            System.out.println("\t4.链表的冒泡排序\\n");
            System.out.println("\t5.链表的插入排序\\n");
            System.out.println("\t0.退出\\n");
            System.out.print("\t请选择：");

            int sc = -1;
            try{
                Scanner scanner = new Scanner(System.in);
                sc = scanner.nextInt();
            }catch (Exception e) {
                System.out.println("错误有误,请重新输入");
            }
            switch (sc){
                case 1:{
                    runQuickSort();
                    break;
                }
                case 2:{
                    runSelectSort();
                    break;
                }
                case 3:{
                    runMergeSort();
                    break;
                }
                case 4:{
                    runBubbleSort();
                    break;
                }case 5:{
                    runInsertSort();
                    break;
                }
                case 0:{
                    flag = false;
                    break;
                }
                default:{
                    System.out.println("输入有误，请重新输入：");
                    break;
                }
            }
        }
    }


    public void runQuickSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortLink so = new SortLink();
        so.quickSortLink();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("链表的快速排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("链表快速排序完毕");

    }


    public void runSelectSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortLink so = new SortLink();
        System.out.println("正在进行链表的选择排序中，此过程大概持续40s，请耐心等待！！");
       so.selectSortLink();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("链表的选择排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("选择排序完毕！！");


    }

    public void runBubbleSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortLink so = new SortLink();
        System.out.println("正在进行链表冒泡排序中，此过程大概持续14s，请耐心等待！！");
        so.BublleSort();
        long totalMilliSeconds02 = System.currentTimeMillis();

        System.out.print("链表的冒泡排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("冒泡排序完毕！！");


    }


    public void runInsertSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortLink so = new SortLink();
        System.out.println("正在排序中，此过程大概持续10s,请耐心等待！！！");
        so.insertSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("插入排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("插入排序完毕");
    }

    public void runMergeSort() throws IOException {
        long totalMilliSeconds = System.currentTimeMillis();
        SortLink so = new SortLink();
        so.mergeSort();
        long totalMilliSeconds02 = System.currentTimeMillis();
        System.out.print("归并排序所用时间：" );
        System.out.println(totalMilliSeconds02 - totalMilliSeconds);
        System.out.println("归并排序完毕");
    }

}
